package com.ericsson.entironment.manager;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ericsson.common.db.DatabaseMng;

public class FrameManager
{
	private static Log log =LogFactory.getLog(FrameManager.class);
	public static String getFrameName(String typeid,String frameid)
	{
		Connection conn = null;
		Statement stmt = null;
		ResultSet rst = null;
		String sql = "";
		try
		{
			conn = DatabaseMng.getInstance().getConnection();
			stmt = conn.createStatement();
			
			sql="select * from EMA_MSGDefine where msgdateid='"+typeid+"' and frameid='"+frameid+"'";
			rst=stmt.executeQuery(sql);
			if (rst.next())
			{
				return rst.getString("framename");
			}
			else
			{
				return "undefine";
			}

		}
		catch (Exception e)
		{
			log.error("execute sql error ["+sql+"]",e);
		}
		finally
		{
			try
			{
				if (rst != null)
					rst.close();
				if (stmt != null)
					stmt.close();
				if (conn != null)
					conn.close();
			}
			catch (Exception e)
			{

			}

		}
		return "";
	}
	
	/**
	 * 获取帧数据类型id对应的帧数据信息
	 */
	public static Map<String, String> getFrameInfo(String msgdateid)
	{
		Connection conn = null;
		Statement stmt = null;
		ResultSet rst = null;
		String sql = "";
		Map<String,String> frameInfo=new HashMap<String,String>();
		try
		{
			conn = DatabaseMng.getInstance().getConnection();
			stmt = conn.createStatement();
			sql="select * from EMA_MSGDefine where msgdateid='"+msgdateid+"'";
			rst=stmt.executeQuery(sql);
			while(rst.next())
			{
				frameInfo.put(rst.getString("frameid"),rst.getString("framename"));
			}

		}
		catch (Exception e)
		{
			log.error("execute sql error ["+sql+"]",e);
		}
		finally
		{
			try
			{
				if (rst != null)
					rst.close();
				if (stmt != null)
					stmt.close();
				if (conn != null)
					conn.close();
			}
			catch (Exception e)
			{

			}

		}
		return frameInfo;
	}
}
